package com.example.androidpattern.state.classes;

import com.example.androidpattern.state.interfaces.IState;

/**
 * @ClassName: VendingMachine$
 * @Description: java类作用描述
 * @Author: xinya
 * @CreateDate: 2020/11/11$ 17:24$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class VendingMachine {
    private int goodsCount = 0;
    private IState currentState;
    private IState noMoneyState;
    private IState hasMoneyState;
    private IState soldState;
    private IState soldOutState;
    private IState winState;

    public VendingMachine(int goodsCount) {
        this.goodsCount = Math.max(goodsCount, 0);
        noMoneyState = new NoMoneyState(this);
        hasMoneyState = new HasMoneyState(this);
        soldState = new SoldState(this);
        soldOutState = new SoldOutState(this);
        winState = new WinState(this);
        currentState = noMoneyState;
    }

    public void insertMoney() {
        currentState.insertMoney();
    }

    public void outMoney() {
        currentState.outMoney();
    }

    public void chooseGoods() {
        currentState.chooseGoods();
    }

    public void outGoods() {
        currentState.outGoods();
    }

    public void setState(IState state) {
        this.currentState = state;
    }

    public void setGoodsCount(int goodsCount) {
        this.goodsCount = goodsCount;
    }

    public IState getCurrentState() {
        return currentState;
    }

    public IState getNoMoneyState() {
        return noMoneyState;
    }

    public IState getHasMoneyState() {
        return hasMoneyState;
    }

    public IState getSoldState() {
        return soldState;
    }

    public IState getSoldOutState() {
        return soldOutState;
    }

    public int getGoodsCount() {
        return goodsCount;
    }

    public IState getWinState() {
        return winState;
    }

    public void setWinState(IState winState) {
        this.winState = winState;
    }
}
